$(document).ready(function()
{
	$('#dateLastVisitMin').datepicker();
	$('#dateLastVisitMax').datepicker();
	$('#dateLastVisit').datepicker();
	$('#DoB').datepicker();
	
	$('#divDoB').hide();
	$('#divDateLastVisit').hide();
	
	// add click event to btnShowDoB
	$('#btnShowDoB').click(function()
	{
		$('#divDoBRange').hide();
		$('#divDoB').show().animate({ backgroundColor: "#4186D3"}, "fast").animate({backgroundColor: "#FFFFFF"}, "fast");
		
		$('#minAge').val('');	// clear out unused fields
		$('#maxAge').val('');	 
	});
	
	// add click event to btnShowDoBRange
	$('#btnShowDoBRange').click(function()
	{
		$('#divDoBRange').show().animate({ backgroundColor: "#4186D3"}, "fast").animate({backgroundColor: "#FFFFFF"}, "fast");
		$('#divDoB').hide();
		
		$('#DoB').val('');		// clear out unused field
	});
	
	// add click event to btnShowDateLastVisit
	$('#btnShowDateLastVisit').click(function()
	{
		$('#divDateLastVisitRange').hide();
		$('#divDateLastVisit').show().animate({ backgroundColor: "#4186D3"}, "fast").animate({backgroundColor: "#FFFFFF"}, "fast");
		
		$('#dateLastVisitMin').val('');		// clear out unused field
		$('#dateLastVisitMax').val('');		// clear out unused field
	});
	
	// add click event to btnShowDateLastVisitRange
	$('#btnShowDateLastVisitRange').click(function()
	{
		$('#divDateLastVisitRange').show().animate({ backgroundColor: "#4186D3"}, "fast").animate({backgroundColor: "#FFFFFF"}, "fast");
		$('#divDateLastVisit').hide();
		
		$('#dateLastVisit').val('');		// clear out unused field
	});
	
	// when clicked, this adds a new row for medications after the first medications row
	$('#btnAddMedication').click(function()
	{
		$("<tr><td></td><td><input name='medications' type='text' /></td>").insertAfter('#trMedications').animate({ backgroundColor: "#4186D3"}, "fast").animate({backgroundColor: "#FFFFFF"}, "fast");
		
		//$('#trMedications').after(
		//"<tr><td></td><td><input name='medications' type='text' /></td>"
		//);
	});
	
	// when clicked, this adds a new row for allergies after the first allergy row
	$('#btnAddAllergy').click(function()
	{
		$("<tr><td></td><td><input name='allergies' type='text' /></td>").insertAfter('#trAllergies').animate({ backgroundColor: "#4186D3"}, "fast").animate({backgroundColor: "#FFFFFF"}, "fast");
		
		//$('#trAllergies').after(
		//"<tr><td></td><td><input name='allergies' type='text' /></td>"
		//);
	});
	
	// load jQuery Validation
	$("#criteria").validationEngine('attach');
	
	// clear fields because the browser will cache old fields
	clearValues();
});

// clear all fields because the browser will cache fields
function clearValues()
{	
	$('#firstName').val('');
	$('#lastName').val('');
	$('#minAge').val('');
	$('#maxAge').val('');
	$('#race').val('--');
	$('#gender').val('--');
	$('#insurance').val('');
	$('#city').val('');
	$('#state').val('');
	$('#country').val('');
	$('#drLastName').val('');
	$('#religion').val('');
	$('#bloodType').val('--');
	$('#postalCode').val('');
	$('.medications').val('');
	$('.allergies').val('');
	$('#dateLastVisitMin').val('');
	$('#dateLastVisitMax').val('');
	$('#reason').val('');
	$('#DoB').val('');
	$('#dateLastVisit').val('');
	document.getElementById("defaultAllergiesCombinationType").checked = true;
	document.getElementById("defaultMedicationsCombinationType").checked = true;
	//$('#').val('');
}